import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ThirdWindow {

    public void Window31() {

        // 创建第三个窗口
        JFrame Third1Frame = new JFrame("收入");
        Third1Frame.setBounds(450,300,500,500);
        Third1Frame.setLayout(new BorderLayout());
        Third1Frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JPanel topPanel1 = new JPanel(new GridLayout(2, 1));
        JPanel bottomPanel1 = new JPanel();

        // 创建组件
        JLabel incomeAmountLabel = new JLabel("     收入金额：");
        incomeAmountLabel.setFont(new Font("宋体", Font.PLAIN, 20));
        JTextField incomeAmountField = new JTextField();

        JLabel incomeReasonLabel = new JLabel("     收入原因：");
        incomeReasonLabel.setFont(new Font("宋体", Font.PLAIN, 20));
        JTextField incomeReasonField = new JTextField();



        JButton nextButton = new JButton("下一步");

        Tool tool = new Tool();
        nextButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // 更新主窗口数据
                double incomeAmount = Double.parseDouble(incomeAmountField.getText());

                tool.updateMainWindowData1(incomeAmount);

                // 打开第四个窗口
                if(!FirstWindow.flag) {
                    FourthWindow fourthWindow = new FourthWindow();
                    fourthWindow.Window4();
                    FirstWindow.flag = true;
                }
                tool.updateFourth(incomeAmount,incomeReasonField.getText());


                // 关闭第二个窗口
                Third1Frame.dispose();
            }
        });

        // 将组件添加到第二个窗口
        topPanel1.add(incomeAmountLabel);
        topPanel1.add(incomeAmountField);
        topPanel1.add(incomeReasonLabel);
        topPanel1.add(incomeReasonField);

        bottomPanel1.add(nextButton);

        Third1Frame.add(topPanel1,BorderLayout.CENTER);
        Third1Frame.add(bottomPanel1,BorderLayout.SOUTH);

        // 显示第二个窗口
        Third1Frame.pack();
        Third1Frame.setSize(600,300);
        Third1Frame.setVisible(true);
    }

    public void Window32() {

        // 创建第三个窗口
        JFrame Third2Frame = new JFrame("记账");
        Third2Frame.setBounds(450,300,500,500);
        Third2Frame.setLayout(new BorderLayout());
        Third2Frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JPanel topPanel1 = new JPanel(new GridLayout(2, 1));
        JPanel bottomPanel1 = new JPanel();


        // 创建组件

        JLabel expenseAmountLabel = new JLabel("     支出金额：");
        expenseAmountLabel.setFont(new Font("宋体", Font.PLAIN, 20));
        JTextField expenseAmountField = new JTextField();

        JLabel expenseReasonLabel = new JLabel("     支出原因：");
        expenseReasonLabel.setFont(new Font("宋体", Font.PLAIN, 20));
        JTextField expenseReasonField = new JTextField();

        JButton nextButton = new JButton("下一步");

        Tool tool = new Tool();
        nextButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                // 更新主窗口数据
                double expenseAmount = Double.parseDouble(expenseAmountField.getText());

                tool.updateMainWindowData2(expenseAmount);

                // 打开第四个窗口
                if(!FirstWindow.flag) {
                    FourthWindow fourthWindow = new FourthWindow();
                    fourthWindow.Window4();
                    FirstWindow.flag = true;
                }
                tool.updateFourth(expenseAmount,expenseReasonField.getText());


                // 关闭第二个窗口
                Third2Frame.dispose();
            }
        });

        // 将组件添加到第二个窗口

        topPanel1.add(expenseAmountLabel);
        topPanel1.add(expenseAmountField);
        topPanel1.add(expenseReasonLabel);
        topPanel1.add(expenseReasonField);
        bottomPanel1.add(nextButton);

        Third2Frame.add(topPanel1,BorderLayout.CENTER);
        Third2Frame.add(bottomPanel1,BorderLayout.SOUTH);

        // 显示第二个窗口
        Third2Frame.pack();
        Third2Frame.setSize(600,300);
        Third2Frame.setVisible(true);
    }
}
